package com.xuecheng.content.api;

import com.xuecheng.content.model.dto.BindTeachplanMediaDto;
import com.xuecheng.content.model.dto.SaveTeachplanDto;
import com.xuecheng.content.model.dto.TeachplanDto;
import com.xuecheng.content.model.po.TeachplanMedia;
import com.xuecheng.content.service.TeachplanService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程计划 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
//@RequestMapping("teachplan")
public class TeachplanController {

    @Autowired
    private TeachplanService  teachplanService;

    @ApiOperation("查询课程计划树形结构")
    @ApiImplicitParam(value = "courseId",name = "课程Id",required = true,dataType = "Long",paramType = "path")
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public List<TeachplanDto> findTeachplanTree(@PathVariable Long courseId){

        return teachplanService.findTeachplanTree(courseId);
    }

    @ApiOperation("课程计划创建或修改")
    @PostMapping("/teachplan")
    public void saveTeachplan( @RequestBody SaveTeachplanDto teachplanDto){
        teachplanService.saveTeachplan(teachplanDto);
    }

    @ApiOperation("课程计划删除")
    @ApiImplicitParam(value = "teachPlanId",name = "课程Id",required = true,dataType = "Long",paramType = "path")
    @DeleteMapping("/teachplan/{teachPlanId}")
    public void DeleteTeachplan(@PathVariable Long teachPlanId){
        teachplanService.deleteTeachplan(teachPlanId);
    }

    @ApiOperation("课程计划上移动")
    @PostMapping("/teachplan/moveup/{teachPlanId}")
    public void TeachplanMoveup(@PathVariable Long teachPlanId){
        teachplanService.teachplanMoveup(teachPlanId);
    }

    @ApiOperation("课程计划下移动")
    @PostMapping("/teachplan/movedown/{teachPlanId}")
    public void TeachplanMovedown(@PathVariable Long teachPlanId){
        teachplanService.teachplanMovedown(teachPlanId);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @PostMapping("/teachplan/association/media")
    public TeachplanMedia associationMedia(@RequestBody BindTeachplanMediaDto bindTeachplanMediaDto){
        return teachplanService.associationMedia(bindTeachplanMediaDto);
    }

    @ApiOperation(value = "课程计划和媒资信息绑定")
    @DeleteMapping("/teachplan/association/media/{teachPlanId}/{mediaId}")
    public void associationMedia(@PathVariable Long teachPlanId,@PathVariable String mediaId){
        teachplanService.deleteMedia(teachPlanId,mediaId);
    }
}
